let app = getApp()
Page({
  data: {
    videoType: {
      arr: [ "MP4", "腾讯视频", "抖音", "微视", "腾讯视频插件专用" ],
      index: 0
  },
  classifyArr: {
      arr: [],
      index: 0
  },
  cover:'',
  params: {
      userid:wx.getStorageSync('user_id'),
      title: "",
      class_id: "",
      type: 1,
      url: "",
      screen_orientation: 1,
      cover: ""
  }
  },
  save:function(){
    var that=this
    wx.request({
      url: app.globalData.siteroot,
      data: {
        do:'Video_busAddVideo',
        staff_id:wx.getStorageSync('staff_bind_id'),
        userid:wx.getStorageSync('user_id'),
        title:that.data.params.title,
        class_id:that.data.params.class_id,
        type:that.data.params.type,
        url:that.data.params.url,
        screen_orientation:that.data.params.screen_orientation,
        cover:that.data.cover
      },
      success: function(res) {
         if(res.data.code==0)
         {
          wx.showToast({
            title:res.data.msg,
            icon: 'none',
            duration: 1500
          })
         }else{
          wx.navigateBack({
            delta:1,
            success: function() {
            }
          })
         }
      }
    })
  },
  upShopLogo: function () {
    var that = this;
    wx.showActionSheet({
    itemList: ['从相册中选择', '拍照'],
    success: function (res) {
    if (!res.cancel) {
    if (res.tapIndex == 0) {
           that.chooseWxImageShop('album');
    } else if (res.tapIndex == 1) {
           that.chooseWxImageShop('camera');
        }
      }
     }
    })
  },
  chooseWxImageShop: function (type) {
    var that = this;
    wx.chooseImage({
    sizeType: ['original', 'compressed'],
    sourceType: [type],
    success: function (res) {
    that.data.cover = res.tempFilePaths[0],
    that.upload_file(res.tempFilePaths[0])
    that.setData({
      cover:res.tempFilePaths[0]
         })
       }
     })
    },
    upload_file: function (filePath) {
      var that = this;
      wx.uploadFile({
      url:app.globalData.siteroot+'&do=Index_uploadFile',
      filePath: filePath,
      name: 'file_upload',
      header: {
      'content-type': 'multipart/form-data'
      }, 
      formData: {
      'do':'Index_uploadFile',
      },
      success: function (res) {
      var data=JSON.parse(res.data)
      that.setData({
        cover:data.info.url,
      });
      },
      fail: function (res) {}
      })
  },
  urlchange:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var params=this.data.params
      params['url']=e.detail.value
      this.setData({
        params:params
       })
    }
  },
  videotype:function(e){
    var videoType=this.data.videoType
    videoType['index']=e.detail.value
    var params=this.data.params
    params['type']=parseInt(e.detail.value)+1
    this.setData({
      videoType:videoType,
      params:params
     })
  },
  classchange:function(e){
    var classifyArr=this.data.classifyArr
    classifyArr['index']=e.detail.value
    var params=this.data.params
    params['class_id']=classifyArr.arr[e.detail.value].id
    this.setData({
      classifyArr:classifyArr,
      params:params
     })
  },
  titlechange:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var params=this.data.params
      params['title']=e.detail.value
      this.setData({
        params:params
       })
    }
 },
  choosetype:function(e){
     var params=this.data.params
     params['screen_orientation']=e.detail.value
     this.setData({
       params:params
     })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this
    wx.request({
      url: app.globalData.siteroot,
      data: {
        do:'Video_getVideoClass',
        staff_id:wx.getStorageSync('staff_bind_id')
      },
      success: function(res) {
         var classifyArr=that.data.classifyArr
          classifyArr['arr']=res.data.data
          var params=that.data.params
          params['class_id']=res.data.data[0].id
          that.setData({
            classifyArr:classifyArr,
            params:params
          })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})